package cn.jcby.app.lebu.utils;

import io.swagger.annotations.ApiModel;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: lihaotian
 * @since: 2023/12/7 12:11
 * @description
 **/
@ApiModel(
        value = "接口返回对象",
        description = "接口返回对象"
)
public class Result extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;
    public static final Integer INTERNAL_SERVER_ERROR_500 = 500;
    public static final Integer OK_200 = 200;

    public Result() {
        this.put((String)"code", 0);
        this.put((String)"msg", "操作成功");
    }

    public static Result error() {
        return error(INTERNAL_SERVER_ERROR_500, "服务器异常");
    }

    public static Result error(String msg) {
        return error(INTERNAL_SERVER_ERROR_500, msg);
    }

    public static Result error(int code, String msg) {
        Result r = new Result();
        r.put((String)"code", code);
        r.put((String)"msg", msg);
        return r;
    }

    public static Result ok(String msg) {
        Result r = new Result();
        r.put((String)"msg", msg);
        return r;
    }

    public static Result ok(Map<String, Object> map) {
        Result r = new Result();
        r.putAll(map);
        return r;
    }

    public static Result ok() {
        return new Result();
    }

    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public static Result ok(Object data) {
        Result r = new Result();
        r.put("data", data);
        return r;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof Result)) {
            return false;
        } else {
            Result other = (Result)o;
            return other.canEqual(this);
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof Result;
    }

    @Override
    public int hashCode() {
        return 1;
    }

    @Override
    public String toString() {
        return "Result()";
    }
}
